package com.aftvc.springbootstartdemo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author MtRider
 * @version 1.0
 * @description 本机axios跨域
 * @GiteeAndGithub MtRider
 * @date 2022/8/11 19:32
 */
@Configuration
public class CustomCORSConfiguration extends WebMvcConfigurerAdapter {
    static final String ORIGINS[] = new String[]{"GET", "POST", "PUT", "DELETE"};

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").
                allowedOriginPatterns("*").
                allowCredentials(true).
                allowedMethods(ORIGINS).
                maxAge(3600);
    }
}
